<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
		<meta name="keywords" content="">
		<meta name="description" content="">
		<link rel="stylesheet" href="http://cmanage.shinechain.io/vendor/css/weuix.min.css" />
		<link rel="icon" type="image/png" href="http://cmanage.shinechain.io/imgs/favicon.ico" />
		<title>区块链推广管理中心</title>
	</head>
	<style>
		body{
			background: #ffffff;
		}
		.main{
			width: 80%;
			margin: 0 auto;
		}
		.main>.title{
			text-align: center;
			margin-top: 5%;
		}
		#template{
			display: none;
		}
	</style>

	<body>
		<div class='main' style="position: relative;">
			<a href="/telegram.html" style="position: absolute; top: -10px;"><img src="http://cmanage.shinechain.io/imgs/return.jpg" height="48" width="48" style="vertical-align:middle;" /></a>
			<p>
				<h2 class='title'>抢口令红包送Token<h2></p>
	
	<div>
       <br />
       	
    </div>
    
    <h3>发送口令红包：</h3>
                输入口令<input type="text" id='tokenName' size="30" placeholder="当用户发送/key 口令 即可领取红包"/>当用户发送/key 口令 即可领取红包<br />
                输入红包数量<input type="text" id='amount' size="2"/><br />
                输入总币额<input type="text" id='rewardTotal' size="2"/><br />
                <input type="button" id="formSubmitBtn" value="发红包"/>
       			<div>
       				<br />
       			</div>
   
 <div id='template' class='block'>
		<div class='ctrl'>
			{{index}}{{name}}
			<input class="weui_switch" type="checkbox" {{checked}} data-slug='{{slug}}'>
		</div>
	</div>
	
</div>
<table id="table" border="1" cellspacing="0" cellpadding="0" align="center" style="font-size: large;left: 300px;position: relative;">
	<caption>红包领取详情：</caption>
	<tbody>
	   <tr>
	        <th>电报Id</th>
	        <th>电报昵称</th>
	        <th>领取红包数</th>
	        <th>已获Token</th>
	    </tr>
    </tbody>
</table>
<br />
<table id="table2" border="1" cellspacing="0" cellpadding="0" align="center" style="font-size: large;left: 900px;top:-130px;position: relative;">
	<caption>红包发送记录：</caption>
	<tbody>
	   <tr>
	        <th> 口 令 </th>
	        <th>数 量</th>
	        <th>金 额</th>
	    </tr>
    </tbody>
</table>
		<script src='http://cmanage.shinechain.io/vendor/js/zepto.min.js'></script>
<script>
$(function(){
	var ip = 'http://bot.shinechain.io';
			
	
 	var getInfo = function () {
			$.get(ip + '/botApi/getRedPaper', function(res) {
		        //input
		        //table
		        var table=document.getElementById("table");
				var data = res.redPaperCount;
				$.each(data,function(key,values){
					var row=table.insertRow(table.rows.length);
					var c1=row.insertCell(0);
					c1.innerHTML=values.telegrameId;
					var c2=row.insertCell(1);
					c2.innerHTML=values.telegramName;
					var c1=row.insertCell(2);
					c1.innerHTML=values.redPaperCount;
					var c2=row.insertCell(3);
					c2.innerHTML=values.tokenCount;
    				});   
    				
    			var table2=document.getElementById("table2");
				var data2 = res.rewardList;
				$.each(data2,function(key,values){
					var row2=table2.insertRow(table2.rows.length);
					var c1=row2.insertCell(0);
					c1.innerHTML=values.token;
					var c2=row2.insertCell(1);
					c2.innerHTML=values.amount;
					var c1=row2.insertCell(2);
					c1.innerHTML=values.rewardtotal;
    				});

                $('#tokenName').val(res.tokenName);
                $('#amount').val(res.amount);
                $('#rewardTotal').val(res.rewardTotal);
 			});  
			
	}
			getInfo();		
  
  	var clickToken = function (){
  		$('#formSubmitBtn').click(function(){
		var tokenName = $('#tokenName').val();
		var amount = $('#amount').val();
		var rewardTotal = $('#rewardTotal').val();
		var jsonArr = {tokenName,amount,rewardTotal};
		$.ajax({
                url: ip + '/botApi/openRedPaper',
                type: 'POST',
                contentType: "application/json; charset=utf-8",
                dataType: 'json',
                data: JSON.stringify(jsonArr),
                success: function(res) {
                	if(res.status==200){
                	$('#token').text(res.token);
                	$('#tokenDayTimes').text(res.tokenDayTimes);
                	window.alert('红包发送成功');
                	}
                	else{
                		window.alert(res.errorMsg);
                	}
                },
      		 })
  		});
  	}
  clickToken();
 
})
</script>
</body>
</html>